#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long double Data;
vector<vector<Data>> factor;
vector<Data> constant;
vector<pair<Data, Data>> pointList;
size_t pointAmount;
size_t fittingDim;
const Data eps = 1e-18;
Data xBase;
inline Data X(size_t idx)
{
    return pointList[idx].first;
}
Data sgn(Data x)
{
    if (abs(x) < eps)
        return 0;
    return x > 0 ? 1 : -1;
}
inline Data Y(size_t idx)
{
    return pointList[idx].second;
}
Data power(Data a, size_t b)
{
    Data ret = 1;
    while (b) {
        if (b & 1)
            ret = ret * a;
        a = a * a;
        b >>= 1;
    }
    return ret;
}
void PutX()
{
    if (sgn(xBase) == 0)
        cout << "x";
    else
        cout << "(x" << ((sgn(xBase) == 1) ? "-" : "+") << abs(xBase) << ")";
}
int main()
{
    //    cout << "type the time of the exponential fitting function : ";
    //    cin >> fittingDim;
    fittingDim = 1;
    cout << "type x-coordinate base:";
    cin >> xBase;
    cout << "type the amount of the points:";
    cin >> pointAmount;
    cout << "type the points as \"x y\":" << endl;
    for (size_t i = 0; i < pointAmount; i++) {
        Data x, y;
        cout << "point\t" << i << ":";
        cin >> x >> y;
        assert(y > 0);
        pointList.push_back({x - xBase, log(y)});
    }
    factor =
        vector<vector<Data>>(fittingDim + 1, vector<Data>(fittingDim + 1, 0));
    constant = vector<Data>(fittingDim + 1);
    for (size_t k = 0; k <= fittingDim; k++) {
        for (size_t i = 0; i < pointAmount; i++) {
            for (size_t j = 0; j <= fittingDim; j++)
                factor[k][j] += power(X(i), j + k);
            constant[k] += power(X(i), k) * Y(i);
        }
    }
    size_t r = 0, c = 0;
    for (; c <= fittingDim; c++) {
        size_t t = r;
        for (size_t i = r; i <= fittingDim; i++)
            if (abs(factor[i][c]) > abs(factor[t][c]))
                t = i;
        if (abs(factor[t][c]) < eps)
            continue;
        for (size_t i = 0; i <= fittingDim; i++)
            swap(factor[r][i], factor[t][i]);
        swap(constant[r], constant[t]);
        for (size_t i = c + 1; i <= fittingDim; i++)
            factor[r][i] /= factor[r][c];
        constant[r] /= factor[r][c];
        factor[r][c] = 1;
        for (size_t i = 0; i <= fittingDim; i++) {
            if (i == r)
                continue;
            Data d = factor[i][c];
            for (size_t j = 0; j <= fittingDim; j++)
                factor[i][j] -= factor[r][j] * d;
            constant[i] -= constant[r] * d;
        }
        r++;
    }
    bool fitable = true;
    while (r <= fittingDim) {
        if (abs(constant[r]) > eps)
            break;
        r++;
    }
    cout << "f(x)=exp(";
    bool typed = false;
    cout << fixed;
    for (int i = fittingDim; i >= 0; i--) {
        if (abs(constant[i]) < eps && (i || typed))
            continue;
        if (sgn(constant[i]) == -1 || typed)
            cout << ((sgn(constant[i]) == 1) ? "+" : "-");
        typed = true;
        if (abs(abs(constant[i]) - 1) > eps || !i)
            cout << abs(constant[i]);
        if (i)
            PutX();
        if (i > 1)
            cout << "^" << i;
    }
    cout << ")";
    cout << endl;

    return 0;
}
